Skip to content

Conversation

@raythurnvoid
Copy link
Contributor

@raythurnvoid raythurnvoid commented Jun 26, 2025

Should prevent misunderstandings like #16092

This PR clarifies in the testing documentation that testing examples should not use $state for arrays that are mutated. It also adds a separate untrack section in the $effect documentation to warn users about updating $state values while depending on those same values within an effect.

This should help clarify common misunderstandings users have when dealing with $state versus regular variables.

Before submitting the PR, please make sure you do the following

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • Prefix your PR title with feat:, fix:, chore:, or docs:.
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.
  • If this PR changes code within packages/svelte/src, add a changeset (npx changeset).

Tests and linting

  • Run the tests with pnpm test and lint the project with pnpm lint

@svelte-docs-bot
Copy link

@github-actions
Copy link
Contributor

Playground

pnpm add https://pkg.pr.new/svelte@16247

@Rich-Harris
Copy link
Member

Thank you. I'm averse to having 'side-quests' in the docs, so I got to thinking about how we can make this situation more self-explanatory, and #16405 is what I came up with — it tightens up the error message to make it clear that it's happening because an effect reads and writes the same piece of state, logs the site of that state change to eliminate any guesswork, and fleshes out the docs page that the error message links to. As such I'll close this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants